#!/usr/bin/python
# author dennis
# 2022年06月15日
# 需求：
# 1.定义两个函数，实现循环100万次，每循环一次给全局变量加1
# 2.创建两个子线程执行对应的两个函数，查看计算后的结果
import threading

g_num = 0


def sum_num():
    for i in range(1000000):
        global g_num
        g_num += 1
    print("g_num:", g_num)


def sum_num2():
    for i in range(1000000):
        global g_num
        g_num += 1
    print("g_num:", g_num)


if __name__ == '__main__':
    sum_num_thread = threading.Thread(target=sum_num)
    sum_num2_thread = threading.Thread(target=sum_num2)

    sum_num_thread.start()
    sum_num2_thread.start()
